package com.mzz.structure.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author xushijian
 * @date 18/6/4 下午1:18
 */
public class Test2 {

    public static void main(String[] args) {

        IPersonDao personDao = (IPersonDao) Proxy.newProxyInstance(IPersonDao.class.getClassLoader(), new Class[]{IPersonDao.class}, new InvocationHandler() {

            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                proxy = new PersonDaoImpl();
                return method.invoke(proxy, args);
            }
        });

        System.out.println("result is ...");
        personDao.say();
    }
}
